<?php
namespace Modules\Admin\Http\Controllers;
use Illuminate\Http\Request;
use Modules\Admin\Http\Requests\CommonStatusRequest;
use Modules\Admin\Http\Requests\CommonDeleteRequest;
use Modules\Admin\Models\User as UserModel;
use Modules\Admin\Models\Image as ImageModel;
use Modules\Admin\Http\Controllers\CommonController;
class UserController extends CommonController
{
	/**
	 * @name  列表
	 */
    public function index()
    { 
		$status = UserModel::common_status();
        return view('admin::user.index',compact('status'));
    }
	/**
	 * @name  列表数据
	 */
	 
    public function data(Request $request)
    {
	    $model = UserModel::query();
		$params = $request->all();
		$model = query_condition($model,$params,'phone|nick_name'); 
        $res = $model->with('image_one')->orderBy('id','desc')  
				->paginate($params['limit'])
				->toArray();
		$res['data'] = (new UserModel())->data_image($res['data']);		
        return response()->json(['code' => 0, 'msg'   => config('admin.limit_msg'),'count' => $res['total'],'data'  => $res['data'],'rel'=>1]);
    }
	/**
	 * @name  调整菜单状态数据处理
	 */
    public function status(CommonStatusRequest $request,$id)
    {
		return (new UserModel())->blog_status_update($request->all(),$id,route('admin.user.index')); 
    }
	/**
	 * @name  删除数据处理
	 */
    public function destroy(CommonDeleteRequest $request)
    {
		$id = (new ImageModel())->del_image('users',$request->get('id'));
		if(!is_numeric($id)){
			return $id;
		};
		return (new UserModel())->blog_user_destroy($id,route('admin.user.index'));  
    }
}
